<template>
  <div class="order-content">
    <!-- 头部 -->
    <div class="header">
        <div class="acvator">
            <img :src="userInfo.avatar" alt="" class="img">
        </div>
        <div class="info">
            <div class="nickname">{{userInfo.shop_name}}</div>
            <div class="user">{{ userInfo.mobile }}</div>
            <div class="user">店主：{{ userInfo.nickname }}</div>
        </div>
        <div class="level">
            <img src="../../../assets/shop/star.png" alt="" class="img">
          {{ userInfo.shop_level }}</div>
    </div>
    <!-- 收益 -->
    <div class="profit">
        <div class="shop-total item">
            <div class="title">
                店铺总收益(元)
            </div>
            <div class="amount">{{ userInfo.shop_total }}</div>
        </div>
        <div class="today-forecast item">
            <div class="title">
                预计今日收益(元)
            </div>
            <div class="amount">{{ userInfo.shop_today }}</div>
        </div>
    </div>
    <!-- tab栏 -->
    <div class="tabs-title">
        <div class="title">
            <div class="active">待发货</div>
            <div @click="toGoodsManager">商品管理</div>
            <div @click="toSupplier">1314义乌小镇</div>
        </div>
    </div>
    <!-- 商品列表 -->
    <div class="goods">
        <div class="content-box">
            <van-list
                v-model="loading"
                :finished="finished"
                finished-text=""
                @load="onLoad"
            >
                <div class="goods-item" v-for="(item, index) in orderList"  :key="index" @click="handleDetail(item.id)">
                    <div class="order-no">
                        <div class="number">订单编号：{{item.order_no}}</div>
                        <div class="status">{{item.state_text}}</div>
                    </div>
                    <div class="goods-content" v-for="goods in item.ordergoods" :key="goods.id">
                        <div class="img">
                            <img :src="goods.image" />
                        </div>
                        <div class="goods-info">
                            <div class="name">{{goods.title}}</div>
                            <div class="number">数量：x{{goods.number}}</div>
                            <div class="amount">￥{{goods.price}}</div>
                        </div>
                    </div>
                    <div class="order-time">订单时间：{{item.createtime_text}}</div>
                    <div class="detail">
                        <van-button round class="btn">查看详情</van-button>
                    </div>
                </div>
            </van-list>
        </div>
    </div>
  </div>
</template>

<script>
import { orderIndex ,userInfo5G} from "@/api/api";
export default {
    name: "orderList",
    components: {
    },
    data(){
        return {
            shop_id:'',
            orderList:[],
            activeIndx: 0,
            page:0,
            loading:false,
            finished:false,
            userInfo:{}
        }
    },
    mounted(){
        this.getUserInfo()
    },
    methods:{
        onLoad(){
            if(this.navlist && this.navlist.length > 0){
                this.orderIndex(this.navlist[this.activeIndx].id,this.page)
            }
        },
        orderIndex(page = 0){
            if(page == 0){
                this.list = []
                this.finished = false
                this.loading = true
            }
            page++
            this.page = page
            //待发货订单
            orderIndex({shop_id:this.shop_id,page,state:'2'}).then(res=>{
               if (res.data.code == 1){
                this.orderList = res.data.data.data
                this.loading = false;
                if(res.data.data.total <= this.orderList.length || this.page >= res.data.data.last_page){
                    this.finished = true
                }
                }
            })
        },
        toGoodsManager(){
            this.$router.push("/goodsManager");
        },
        toSupplier(){
            this.$router.push("/supplier");
        },
        handleDetail(orderId){
            this.$router.push({
                path:"/shopOrderDetail/" + orderId ,
                query:{orderId}
            })
        },
        getUserInfo(){
          userInfo5G({token5g:localStorage.getItem("token5g")}).then(res=>{
            this.userInfo = res.data.data
            this.shop_id = res.data.data.shop_id
            this.orderIndex()
          })
        }
    }
}
</script>

<style scoped>
div {
    box-sizing: border-box;
}
.order-content {
    background-color: #F8F8F8;
}
.header {
    position: relative;
    height: 260px;
    background-image: linear-gradient( to bottom , #FAEEEC 0%, #FAEEEC 80%, #fff 100%);
    padding: 60px 20px 120px;
    display: flex;
    align-items: center;
}

.header .acvator {
    width: 70px;
    height: 70px;
}
.header .acvator .img {
    width: 100%;
    height: 100%;
}
.header .info {
    height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-left: 20px;
    font-size: 12px;
}
.header .info .nickname {
    font-size: 18px;
}

.header .level {
    font-size: 12px;
    position: absolute;
    bottom: 120px;
    right: 20px;
    background-color: #fff;
    width: 120px;
    height: 30px;
    border-radius: 15px;
    color: #FB5340;
    display: flex;
    justify-content: center;
    align-items: center;
}
.header .level .img {
    width: 20px;
    margin-right: 5px;
}

.profit{
    position: relative;
    margin: -100px 10px 0 10px;
    height: 100px;
    border-radius: 10px;
    border: 2px solid #fff;
    background-image: linear-gradient( to right , #F7E8D1 , #F5E2C4);
    display: flex;
    justify-content: space-around;
    align-items: center;
}
.profit .item {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    padding: 20px 0;
    color: #873A11;
}

.profit .item .title {
    font-size: 10px;
}
.profit .item .amount {
    font-size: 20px;
    font-weight: 700;
}



.tabs-title {
    margin-top: 10px;
    height: 50px;
    background-color: #fff;
    box-shadow: 0 0 15px 10px #f8f8f8;
}
.tabs-title .title {
    padding: 10px;
    display: flex;
    padding-bottom: 15px;
    line-height: 25px;
    font-size: 14px;
}
.tabs-title .title div {
    flex: 1;
    text-align: center;
}
.tabs-title .title .active {
    color: #FA382B;
    position: relative;
}
.tabs-title .title .active::after{
    content: '';
    position: absolute;
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 35px;
    height: 2px;
    background-color: #FA382B;
}


.goods {
    margin: 10px 10px 0 10px;
    display: flex;
    height: calc(100vh - 350px);
    color: #A3A2A2;
}

.content-box {
    width: 100%;
    height: 100%;
    overflow: scroll;
}
.content-box::-webkit-scrollbar {display: none;}
.goods-item {
    border-radius: 8px;
    width: 100%;
    padding: 0 10px;
    margin-bottom: 10px;
    background-color: #fff;
    font-size: 14px;
}

.goods-item .order-no {
    line-height: 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
}
.goods-item .order-no .status {
    color: #FB784E;
}
.goods-item .goods-content {
    padding: 10px 0;
    display: flex;
    border-bottom: 1px solid #eee;
}

.goods-item .goods-content .img {
    width: 80px;
    height: 80px;
    border-radius: 5px;
    overflow: hidden;
}
.goods-item .goods-content .img img {
    width: 100%;
    height: 100%;
}

.goods-item .goods-content .goods-info{
    margin-left: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.goods-item .goods-content .goods-info .name {
    line-height: 20px;
    color: #000;
    font-size: 16px;
}
.goods-item .goods-content .goods-info .amount {
    color: #F96748;
    font-size: 16px;
}
.goods-item .order-time{
    line-height: 40px;
}
.goods-item .detail {
    padding: 0px 0 10px;
    display: flex;
    justify-content: flex-end;
}
.goods-item .detail .btn {
    height: 30px;
    line-height: 30px;
}
</style>
